import random

res = ["0a0b", "0a1b", "0a2b", "0a3b", "0a4b", "1a0b", "1a1b", "1a2b", "1a3b", "2a0b", "2a1b", "2a2b", "3a0b", "3a1b", "4a0b"]

def judge(ans, gue):
    a = b = 0
    for i in range(0,4):
        if ans[i] == gue[i]:
            a += 1
        elif gue[i] in ans:
            b += 1
    return str(a) + "a" + str(b) + "b"

def sep(a, gue):
    b = {}
    global res
    for i in res:
        b[i] = []
    for i in a:
        b[judge(i, gue)].append(i)
    return b

def getmax(a):
    t = 0; m = ""
    for i in a:
        if len(a[i]) > t:
            t = len(a[i])
            m = i
    return t, m

if __name__ == "__main__":
    p = []
    All = []
    for i in range(0, 10000):
        All.append(str(i // 1000) + str(i // 100 % 10) + str(i // 10 % 10) + str(i % 10))
        p.append(All[i])
    cnt = 0
    c = int(input("Who guess?\n1:Computer 2:Human\n"))
    if c == 1:
        while True:
            print("Computer Thinking...\nIt may take at most 3 minutes.")
            m = 10001
            x = ""
            for i in All:
                #if i[2] == '0' and i[3] == '0':
                #    print("Testing", i)
                t, z = getmax(sep(p, i))
                if t < m:
                    m = t; x = i
            print("Guess:", x); cnt += 1
            tmp = input("Result: ")
            if tmp == "4a0b":
                print(cnt - 1, "time(s)")
                break
            p = sep(p, x)[tmp]
            if len(p) == 0:
                print("You've had a mistake!")
                break
    elif c == 2:
        while True:
            tmp = input("Guess: ")
            k = sep(p, tmp)
            t, z = getmax(k)
            print("Result:",z); cnt += 1
            if z == "4a0b":
                print("You Win!")
                print(cnt, "time(s)")
                break
            p = k[z]
            print(p)